import { GameResult } from "./GameResult";
import { RoomGameInfo } from "./RoomGameInfo";
import { RoomPlayer } from "./RoomPlayer";

export class VideoInfo {

    public id: number;
    public gameResultId: number;
    public ju: number; //第几局
    public time: number;
    public begin_gameInfo: RoomGameInfo
    public playerList: Array<RoomPlayer> = []

    public actionList: Array<object> = []
    public videoResult: object

    public gameResult: GameResult

    public db2ModelBase(data: object, gameResult: GameResult) {
        this.gameResult = gameResult;
        this.id = data["id"]
        this.gameResultId = data["gameResultId"]
        this.ju = data["ju"]
        this.time = new Date(data["time"]).getTime();
        this.begin_gameInfo = JSON.parse(data["begin_gameInfo"]) as RoomGameInfo
        let playerObjList: Array<object> = JSON.parse(data["playerList"])
        this.initPlayerList(playerObjList);
        this.videoResult = JSON.parse(data["videoResult"])
    }

    public initPlayerList(playerList: Array<object>) {
        for (let i = 0; i < playerList.length; i++) {
            if (playerList[i]) {
                let player: RoomPlayer = RoomPlayer.createPlayerByObj(playerList[i])
                this.playerList[i] = player;
            } else {
                this.playerList[i] = null
            }
        }
    }

    public clone() {
        let model: VideoInfo = new VideoInfo()
        model.id = this.id
        model.gameResultId = this.gameResultId
        model.ju = this.ju
        model.time = this.time
        model.begin_gameInfo = Object.assign({}, this.begin_gameInfo);
        model.playerList = this.playerList
        model.actionList = this.actionList
        model.videoResult =  Object.assign({}, this.videoResult);
        model.gameResult =  Object.assign({}, this.gameResult);
        return model
    }

}